<template>
  <div class="login-container">
      <el-row>
        <el-col :span="16">
          
        </el-col>
        <el-col :span="8">
          <div class="_login-wrap">
            <div class="title">
              <div class="title-top">弹</div>
              <div class="title-content">弹性平台登录系统</div>
            </div>
            <el-form class="card-box login-form" 
            autoComplete="on" 
            :model="loginForm" 
            :rules="loginRules" 
            ref="loginForm" 
            label-position="left" 
            label-width="0px">

            <el-form-item prop="companyType">
              <p>公司类型</p>
              <span class="svg-container svg-container_login"><icon-svg icon-class="gongsi" /></span>
              <el-select name="companytype" 
                  v-model="loginForm.companyType"
                  placeholder="公司类型">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item prop="username">
              <p>用户名</p>
              <span class="svg-container svg-container_login"><icon-svg icon-class="yonghuming" /></span>
              <el-input name="username" type="text" 
                  v-model="loginForm.username" 
                  autoComplete="on" 
                  placeholder="登录名" />
            </el-form-item>

            <el-form-item prop="password">
              <p>密码</p>
              <span class="svg-container"><icon-svg icon-class="mima"></icon-svg></span>
              <el-input name="password" type="password" 
                  v-model="loginForm.password" 
                  autoComplete="on" 
                  placeholder="密码" 
                  @keyup.enter.native="handleLogin" />
            </el-form-item>

            <el-form-item prop="managementAgency">
              <p>管理机构</p>
              <span class="svg-container"><icon-svg icon-class="guanlijigou"></icon-svg></span>
              <el-select name="managementAgency" 
                  v-model="loginForm.managementAgency"
                  placeholder="管理机构">
                <el-option
                  v-for="item in agencies"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="default" style="background:#cccccc;width:30%;height:36px" 
                :loading="loading"
                >
                修改
              </el-button>
              <el-button type="primary" style="width:30%;height:36px" 
                :loading="loading" 
                @click.native.prevent="handleLogin">
                登录
              </el-button>
            </el-form-item>

            <div class='tips'>
              <span style="margin-right:20px;">{{tipMsg}}</span>
            </div>

          </el-form>
          </div>
          
        </el-col>
      </el-row>
  </div>
</template>

<script>
import img from '@/assets/bg/timg.png'
export default {
  name: 'login',
  data() {
    return {
      loginForm: {
        companyType:'',
        username: '',
        password: '',
        managementAgency:''
      },
      options: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }
      ],
      agencies: [{
          value: '选项1',
          label: '03'
        }, {
          value: '选项2',
          label: '04'
        }, {
          value: '选项3',
          label: '05'
        }, {
          value: '选项4',
          label: '06'
        }, {
          value: '选项5',
          label: '07'
        }
      ],
      tipMsg: '',
      loginRules: {
        companyType:[
          { required:true ,message:'请输入公司类型', trigger: 'blur'}
        ],
        username: [
          { required: true, message: '请输入登录名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码!!!!', trigger: 'blur' }
        ],
        managementAgency: [
          { required: true, message: '请输入管理机构', trigger: 'blur' }
        ]
      },
      loading: false
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        console.log(valid)
        if (valid) {
          // this.loading = true;
          // this.$store
          //   .dispatch('Login', this.loginForm)
          //   .then(resp => {
          //     this.loading = false
          //     var data = resp.data
          //     if (!data.flag) {
          //       this.tipMsg = data.msg
          //     } else {
          //       this.$router.push({
          //         name: '首页'
          //       })
          //     }
          //   })
          //   .catch(() => {
          //     this.loading = false
          //   })
          this.$router.push({
            name: "home"
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
  // watch:{
  //   loginForm:{
  //     handler:function(val,oval){
  //       console.log(val.username,val.password)
  //     },
  //     deep:true
  //   }
  // }
}
</script>

<style rel="stylesheet/scss" lang="scss">
@import "src/styles/mixin.scss";
@import "src/styles/mixin.scss";
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  @include relative;
  height: 100vh;
  background:url('../../assets/bg/timg.png') no-repeat left top;
  background-size:100vw 100vh;
  input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px #CEC6D1 inset !important;
    -webkit-text-fill-color: #fff !important;
  }
  *{
    box-sizing: border-box;
  }
  input{
    background: #fff;
    border: 0;
    -webkit-appearance: none;
    border-radius: 0;
    padding: 12px 5px 12px 15px;
    // color: $light_gray;
  }
  .el-row{
    width:100vw;
    height:100vh;
    background:url('../../assets/bg/WELCOME.png') no-repeat 76px 294px;
    background-size:500px 60px;
  }
  .el-col {
    height:100%;
  }
  ._login-wrap{
    width:100%;
    height:100%;
    background:#f5f5f5;
  }
  .el-col h2{
    color:$light_gray;
  }
  .el-input,.el-select {
    display: inline-block;
    height: 47px;
    width: 85%;
  }
  .el-select .el-input{
    width:100%;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
  }
  .svg-container {
    padding: 1px 10px;
    color: $dark_gray;
    background:#cccccc;
    vertical-align: middle;
    width: 38px;
    height:38px;
    display: inline-block;
    &_login {
      font-size: 20px;
    }
  }
  .title {
    font-size: 16px;
    font-weight: 400;
    // color: $light_gray;
    // margin: 0 auto 40px;
    padding:60px 35px 0;
    text-align: center;
    font-weight: bold;
  }
  .title-top{
    width:100px;
    height:100px;
    background:#fc8b15;
    color:#fff;
    font-size:40px;
     border-radius: 5px;
    line-height: 100px;
    text-align: center;
    margin:0 auto;
  }
  .login-form {
    width:100%;
    padding: 50px 35px 15px;
    
  }
  .el-form-item {
    border-radius: 5px;
    color: #454545;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
  }
  .thirdparty-button {
    position: absolute;
    right: 35px;
    bottom: 28px;
  }
}
</style>
